package com.java.module.user.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.user.domain.Search;
import com.java.module.user.service.ISearchService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 搜索查询Controller
 * 
 * @author Administrator
 * @date 2025-06-20
 */
@RestController("AdminSearchController")
@RequestMapping("/user/search")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    /**
     * 查询搜索查询列表
     */
    @PreAuthorize("@ss.hasPermi('user:search:list')")
    @GetMapping("/list")
    public TableDataInfo list(Search search) {
        WebKit.startPage();
        List<Search> list = searchService.selectSearchList(search);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出搜索查询列表
     */
    @PreAuthorize("@ss.hasPermi('user:search:export')")
    @Log(title = "搜索查询", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Search search) {
        List<Search> list = searchService.selectSearchList(search);
        ExcelUtil<Search> util = new ExcelUtil<Search>(Search.class);
        return util.exportExcel(list, "search");
    }

    /**
     * 获取搜索查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:search:query')")
    @GetMapping(value = "/{selectId}")
    public AjaxResult getInfo(@PathVariable("selectId") Long selectId) {
        return AjaxResult.success(searchService.selectSearchById(selectId));
    }

    /**
     * 新增搜索查询
     */
    @PreAuthorize("@ss.hasPermi('user:search:add')")
    @Log(title = "搜索查询", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Search search) {
        return WebKit.toAjax(searchService.insertSearch(search));
    }

    /**
     * 修改搜索查询
     */
    @PreAuthorize("@ss.hasPermi('user:search:edit')")
    @Log(title = "搜索查询", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Search search) {
        return WebKit.toAjax(searchService.updateSearch(search));
    }

    /**
     * 删除搜索查询
     */
    @PreAuthorize("@ss.hasPermi('user:search:remove')")
    @Log(title = "搜索查询", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{selectIds}")
    public AjaxResult remove(@PathVariable Long[] selectIds) {
        return WebKit.toAjax(searchService.deleteSearchByIds(selectIds));
    }
}
